﻿using Microsoft.VisualBasic.Devices;
using SanXiao.Game.Common;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace SanXiao.Game.GameCenter.SpecialEffects
{
    public abstract class SpecialEffectsObject : GameObject
    {
        private readonly ImageObject[] _images;
        public SpecialEffectsObject(GameType gameType, Size size, ImageObject[] images)
            : base(gameType, size)
        {
            _images = images;
        }
        public Action<SpecialEffectsObject>? DrawCompleteCallback;
        protected int _imageIndex;
        public override void Draw(Graphics g)
        {
            if (_imageIndex == -1) return;

            var image = _images[_imageIndex];
            IntPtr hdc = g.GetHdc();
            GDI32.DrawImageTransparenc(hdc, image.BitmapPtr, Location.X, Location.Y, image.Width, image.Height, Size.Width, Size.Height);
            g.ReleaseHdc(hdc);
            if (++_imageIndex>=_images.Length)
            {
                _imageIndex = -1;
                DrawCompleteCallback?.Invoke(this);
            }
        }
        
        protected override void DisposeImage()
        {
            base.DisposeImage();
            foreach (var image in _images)
            {
                image.Dispose();
            }
        }
    }
}
